import React, {Component} from 'react';
import './index.less';
import {base} from 'nc-lightapp-front';
import Pagination from 'src/hrpub/common/components/Pagination/index';

class MainTable extends Component {
    constructor(props) {
        super(props);
        this.state = {
            tableHeight: '',
            pk_org: '',
        };
        this.setTableHeight = this.setTableHeight.bind(this);
        this.beforeEventHandle = this.beforeEventHandle.bind(this);
        this.afterEventHandle = this.afterEventHandle.bind(this);
        this.onRowDoubleClick = this.onRowDoubleClick.bind(this);
    }

    componentDidMount() {
        this.setTableHeight();
    }

    setTableHeight() {
        const mainTable = document.getElementsByClassName('main-table');
        if (mainTable[0]) {
            this.setState({
                tableHeight: mainTable[0].clientHeight - 36
            })
        }
    }

    beforeEventHandle(props, moduleId, item, index, value, record) {

    }

    afterEventHandle(props, moduleId, key, value, changedrows, index, record) {

    }

    //表单双击事件
    onRowDoubleClick(record, index) {
        this.props.onRowDoubleClick(record, index)
    }

    //分页事件
    paginationEve(key) {
        this.props.paginationEve(key)
    }

    // 每页显示条数
    pageSizeSelect(val) {
        this.props.pageSizeSelect(val)
    }

    render() {
        const {editTable, orgVal, agreementType, pageInfo, isVisiblePagination} = this.props;
        let tableid = (agreementType&&agreementType.indexOf('hrcm_agreement') === 0) ? agreementType+ 'List' : agreementType;
        return (
            <div className='main-table nc-bill-table-area'>
                {/* 如果是自定义协议加上List */}
                {editTable.createEditTable(tableid, {
                    //showIndex: true,
                    showCheck: true,
                    cancelCustomRightMenu: true,
                    height: this.state.tableHeight,
                    onBeforeEvent: this.beforeEventHandle,
                    onAfterEvent: this.afterEventHandle,
                    onRowDoubleClick: this.onRowDoubleClick,
                })}
                <div className="pagination" style={{display: isVisiblePagination? '' : 'none'}}>
                    {!orgVal.refpk || !agreementType || !pageInfo || pageInfo.total === "" ? "" : <Pagination
                        total={pageInfo.total}
                        pageSize={pageInfo.pageSize}
                        showQuickJumper={true}
                        showSizeChanger={true}
                        // current = {state.pageInfo.pageIndex}
                        onChange={this.paginationEve.bind(this)}
                        onShowSizeChange={this.pageSizeSelect.bind(this)}
                        current = {pageInfo.pageIndex * 1}
                    />}
                </div>
            </div>
        );
    }
}

export default MainTable;
